package com.csjy.migration.hnnd.workflow;

import com.csjy.migration.hnnd.BusinessTool;
import com.csjy.migration.hnnd.DbUtil;
import com.csjy.migration.hnnd.ProgramArgument;
import com.csjy.migration.hnnd.annotation.Task;
import com.csjy.migration.hnnd.business.SourceBusinessData;
import com.fasterxml.jackson.core.JsonProcessingException;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*工作移交审批(item-hand-over-hny)
phs*/

public class ItemHandOverHny extends WorkflowMigration {

  public ItemHandOverHny(DbUtil sourceDbUtil, DbUtil targetDbUtil, SourceBusinessData sourceData, ProgramArgument programArgument, String projectId, String procInstId, Map procInstRow) throws Exception {
    super(sourceDbUtil, targetDbUtil, sourceData, programArgument, projectId, procInstId, procInstRow);
    this.customInitData();
  }


  @Override
  public void customInitData() {
    this.curBizType = "gzyj";
  }

  @Override
  public void customInsertOrUpdateData() {


  }

  @Task("项目移交@原项目经理提交申请")
  public void yxmjltjsq() throws Exception {
    this.curModelMap.put("all", new String[]{"exclusiveGateway1599877832612xyb", "下一步"});
    String managerType = this.getJbpmVarInstValueByName("managerType");
    String applyManagerNameAndCode = this.getJbpmVarInstValueByName("manager" + managerType);
    this.curCustomData.put("manageTypes", "移交申请人：" + managerType + "经理|" + applyManagerNameAndCode);
    this.curCustomData.put("manageType", managerType + "经理");
    this.curAffixType = "bcgdzl";
    this.curAffixTypeCommon = this.curAffixType;


    this.setCommonData(true, null);


  }

  @Task("项目移交@部门经理审核")
  public void bmjlsh() throws Exception {
    this.curModelMap.put("提交分公司", new String[]{"task1535530862659tjfgs", "提交分公司"});
    this.curModelMap.put("不同意", new String[]{"end", "不同意"});
    this.curModelMap.put("提交新项目经理", new String[]{"task1535531800056tjxxmjl", "提交分公司"});
    String managerTypes = this.getJbpmVarInstValueByName("managerType");
    this.curCustomData.put("managerType", managerTypes);
    this.curCustomData.put("manager", this.getJbpmVarInstValueByName("manager" + managerTypes));
    this.curCustomData.put("newManager", this.getJbpmVarInstValueByName("newManager" + managerTypes));
    String subCorp = this.getJbpmVarInstValueByName("subCorp");
    if (subCorp != null && !subCorp.equals("")) {
      List<Map> itemMap = this.sourceDbUtil.selectByParams("select a.orgname from ft_orgnization a where a.orgid='" + subCorp + "'", new ArrayList());
      this.curProcessData.put("yjfgs", itemMap.get(0).get("ORGNAME"));

    }
    String newOrgCode = this.getJbpmVarInstValueByName("newOrgCode");
    if (newOrgCode != null && !newOrgCode.equals("")) {
      List<Map> itemMap = this.sourceDbUtil.selectByParams("select a.orgname from ft_orgnization a where a.orgid='" + newOrgCode + "'", new ArrayList());
      this.curProcessData.put("zpbsc", itemMap.get(0).get("ORGNAME"));

    }
    this.curCustomData.put("yfzr", this.getJbpmVarInstValueByName("managerT"));
    this.curCustomData.put("xfzr", this.getJbpmVarInstValueByName("newManagerT"));

    String s = this.getJbpmVarInstValueByName("manager" + managerTypes);
    this.curCustomData.put("manageTypes", "移交申请人:" + managerTypes + "经理|" + s);

    this.curAffixType = "tjfj";
    this.setCommonData(true, null);

  }

  @Task("项目移交@分公司负责人审批")
  public void fgsfzrsp() throws Exception {
    bmjlsh();
  }

  @Task("项目移交@新分公司负责人接收")
  public void xfgsfzrjs() throws Exception {
    String managerTypes = this.getJbpmVarInstValueByName("managerType");
    this.curModelMap.put("指派办事处", new String[]{"task1535531217465zpbsc", "指派办事处"});
    this.curModelMap.put("提交项目" + managerTypes + "经理", new String[]{"task1535531800056tjxxmjl", "提交新项目经理"});
    String subCorp = this.getJbpmVarInstValueByName("subCorp");
    if (subCorp != null && !subCorp.equals("")) {
      List<Map> itemMap = this.sourceDbUtil.selectByParams("select a.orgname from ft_orgnization a where a.orgid='" + subCorp + "'", new ArrayList());
      this.curProcessData.put("departname", itemMap.get(0).get("ORGNAME"));
    }

    String lczx = "";
    Map wfAffixNotionObjWkFlagZero = this.findFirstWfAffixNotionObjByWkflag(0);
    if (wfAffixNotionObjWkFlagZero.get("STRRESULT") != null && !wfAffixNotionObjWkFlagZero.get("STRRESULT").equals("")) {
      if (wfAffixNotionObjWkFlagZero.get("STRRESULT").toString().startsWith("提交项目" + managerTypes + "经理")) {
        if (managerTypes.equals("A")) {
          lczx = "tjxmaj";
        } else if (managerTypes.equals("B")) {
          lczx = "tjxmbj";
        }
        /*原a 新a*/
        this.curCustomData.put("srcManagerName", BusinessTool.getEmpCode(this.getJbpmVarInstValueByName("manager" + managerTypes)));
        this.curCustomData.put("manager'" + managerTypes + "'", BusinessTool.getEmpCode(this.getJbpmVarInstValueByName("newManager" + managerTypes)));
      } else if (wfAffixNotionObjWkFlagZero.get("STRRESULT").equals("指派办事处")) {
        lczx = "zpbsc";
        String subCorpT = this.getJbpmVarInstValueByName("subCorp");
        if (subCorpT != null && !subCorpT.equals("")) {
          List<Map> itemMap = this.sourceDbUtil.selectByParams("select a.orgname from ft_orgnization a where a.orgid='" + subCorpT + "'", new ArrayList());
          this.curCustomData.put("departname", itemMap.get(0).get("ORGNAME"));
        }
        String orgCodeT = this.getJbpmVarInstValueByName("newOrgCode");
        if (orgCodeT != null && !orgCodeT.equals("")) {
          List<Map> itemMap = this.sourceDbUtil.selectByParams("select a.orgname from ft_orgnization a where a.orgid='" + orgCodeT + "'", new ArrayList());
          this.curCustomData.put("desManagerName", orgCodeT);
          this.curCustomData.put("bscname", itemMap.get(0).get("ORGNAME"));
        }

      }

    }
    this.curProcessData.put("model", lczx);
    this.curCustomData.put("manageType", managerTypes + "经理");
    this.setCommonData(true, null);
  }

  @Task("项目移交@新办事处负责人接收")
  public void xbscfzrjs() throws Exception {
    this.curModelMap.put("提交新项目经理", new String[]{"task1535531800056tjxxmjl", "提交新项目经理"});
    /*        this.curModelMap.put("退回",new String[]{"task1535531217465zpbsc","指派办事处"});*/
    this.curModelMap.put("不同意", new String[]{"task1535530818130bty", "不同意"});
    this.curModelMap.put("不接受", new String[]{"task1535530862659bjs", "不接受"});
    String managerTypes = this.getJbpmVarInstValueByName("managerType");
    String sb = BusinessTool.getEmpCode(this.getJbpmVarInstValueByName("newManager" + managerTypes));
    this.curCustomData.put("manageType", managerTypes + "经理");
    this.curCustomData.put("managerA", sb);
    this.curCustomData.put("managerB", sb);
    this.curCustomData.put("managerC", sb);
    this.curCustomData.put("managerD", sb);
    this.setCommonData(true, null);
  }

  @Task("项目移交@新项目经理确认接受")
  public void xxmjlqrjs() throws Exception {
    this.curModelMap.put("同意", new String[]{"endty", "同意"});
    this.curModelMap.put("不同意", new String[]{"endbty", "不同意"});
    this.setCommonData(true, null);
  }
}
